<?php

class Client_Table_Auction_Attaches extends Apk_Db_Table {

    protected $_name = 'auction_attaches';
    protected $_primary = 'ID';
    public $_ERROR = "";

    public function GetError() {
        return $this->_ERROR;
    }

    public function getDataList($page = 1, $sort = null, $page_count = null, $filters = array()) {
        $sel = $this->getAdapter()->select()
                ->from($this->_name, array($this->_name.'.id', 'file_name', 'name',$this->_name.'.file_path'))                
                ->where($this->_name.".id_lot = ". $filters['id'])
                ->where("is_removed = 0");


        return $this->getList($sel);
    }
    
    public function recordDwnldRequest($data){
    	if(!empty($data)){
    		$data['add_date'] = new Zend_Db_Expr("now()");
    		$tmp_tab_name = $this->_name;
    		$this->_name = 'auction_info_dwnld_request';
    		parent::insert($data);
    		$this->_name = $tmp_tab_name;
    	}
    }
    
    public function getVideoFile($id_lot) {
        $sel = $this->getAdapter()->select()
                ->from($this->_name, array('video_path' => 'file_path' , 'video_name'  => 'file_name'))
                ->where($this->_name.'.type = ?', '7')
                ->where($this->_name.'.id_lot = ?', $id_lot)
                ->where("is_removed = ?", 0)
                ->order($this->_name.'.modify_date');

        $data = $this->getList($sel)->toArray();

        if (!empty($data)) $data = $data[0];

        return $data;
    }
}
